Pengantar dan kredit
Anggaplah Anda seorang bartender. Anda memiliki banyak orang yang bahagia di bar Anda paling sering, tetapi banyak yang hanya minum minuman yang sama dan terlalu sedikit untuk selera Anda dan Anda ingin mengubahnya. Jadi Anda memperkenalkan sistem di mana harga minuman bervariasi, tergantung pada berapa banyak yang telah terjual, tetapi tidak pernah lebih atau lebih murah daripada ambang batas tertentu. Untuk beberapa alasan aneh Anda selalu lupa untuk melacak dengan benar semua minuman yang dijual dan harga dan dengan demikian Anda perlu memikirkan sepotong kode pendek (= mudah diingat!) Yang menghitung untuk Anda mengingat jumlah minuman yang dikonsumsi.
Tantangan ini telah muncul dalam ujian tengah semester pada tahun 2012 di kursus pemrograman fungsional di uni saya dan profesor saya boleh saja mempostingnya di sini. Kami telah memberikan contoh solusi dalam bahasa ujian.
Memasukkan
Masukan Anda akan menjadi daftar string yang tidak mengandung spasi - ini adalah nama minuman yang dijual. Ambil input menggunakan metode input yang disukai dan diterima secara umum.
Keluaran
Output Anda akan menjadi satu nomor - ini adalah pendapatan yang Anda hasilkan malam ini. Berikan output menggunakan pilihan Anda, metode output diterima secara umum.
Apa yang harus dilakukan?
Ini berlaku untuk setiap minuman secara individual:
- Harga awal adalah 10.
- Setiap kali minuman dibeli, harganya ditabrak oleh 1 untuk pembeli berikutnya.
- Harga maksimal adalah 50. Jika minuman telah dibeli seharga 50, harga baru akan menjadi 10 lagi.
Tugas Anda adalah menemukan pendapatan keseluruhan, yang dihasilkan oleh daftar input minuman mengingat aturan di atas.
Jika Anda bertanya-tanya: "50 dolar benar-benar mahal untuk minum!", Ini adalah 50-deci Bucks, jadi 50 * 0,1 * Unit, tapi saya memilih untuk menggunakan 10-50 untuk tidak mengecualikan bahasa tanpa aritmatika floating point.
Yang menang?
Ini adalah kode-golf , jadi kode terpendek dalam byte menang! Aturan standar berlaku.
Kasus Pojok Potensial
Jika daftar input kosong, output harus 0.
Daftar input tidak dapat dianggap disortir berdasarkan minuman.
Contohnya
[] -> 0
["A"] -> 10
["A","B"] -> 20
["A","A","B"] -> 31
["A","B","A"] -> 31
["A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A"] -> 1240
["A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","B","B","B","C","C","D"] -> 1304
["D","A","A","C","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","B","B","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","B","C"] -> 1304
["A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","B","B","B","C","C","D","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A","A"] -> 1304